/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.storebits.testsystem;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.persistence.annotations.Convert;
import org.eclipse.persistence.annotations.TypeConverter;

@Entity
@Table(name = "car")
@NamedQueries({
    @NamedQuery(name = "Car.findAll", query = "SELECT c FROM Car c")})
public class Car implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "registrationNumber")
    private String registrationNumber;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "model")
    private String model;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "brand")
    private String brand;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "colour")
    private String colour;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "kind")
    private String kind;
    @Basic(optional = false)
    @NotNull
    @Column(name = "insurance")
    @TypeConverter (name="booleanToInteger", dataType=Integer.class, objectType=Boolean.class)
    @Convert("booleanToInteger")
    private boolean insurance;
    @Basic(optional = false)
    @NotNull
    @Column(name = "kilometers")
    private int kilometers;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Column(name = "price")
    private BigDecimal price;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "car")
    private Collection<Carreservation> carreservationCollection;

    public Car() {
    }
	//
    public Car(String registrationNumber) {
        this.registrationNumber = registrationNumber;
    }

    public Car(String registrationNumber, String model, String brand, String colour, String kind, boolean insurance, int kilometers, BigDecimal price) {
        this.registrationNumber = registrationNumber;
        this.model = model;
        this.brand = brand;
        this.colour = colour;
        this.kind = kind;
        this.insurance = insurance;
        this.kilometers = kilometers;
        this.price = price;
    }

    public String getRegistrationNumber() {
        return registrationNumber;
    }

    public void setRegistrationNumber(String registrationNumber) {
        this.registrationNumber = registrationNumber;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getColour() {
        return colour;
    }

    public void setColour(String colour) {
        this.colour = colour;
    }

    public String getKind() {
        return kind;
    }

    public void setKind(String kind) {
        this.kind = kind;
    }

    public boolean getInsurance() {
        return insurance;
    }

    public void setInsurance(boolean insurance) {
        this.insurance = insurance;
    }

    public int getKilometers() {
        return kilometers;
    }

    public void setKilometers(int kilometers) {
        this.kilometers = kilometers;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public Collection<Carreservation> getCarreservationCollection() {
        return carreservationCollection;
    }

    public void setCarreservationCollection(Collection<Carreservation> carreservationCollection) {
        this.carreservationCollection = carreservationCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (registrationNumber != null ? registrationNumber.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Car)) {
            return false;
        }
        Car other = (Car) object;
        if ((this.registrationNumber == null && other.registrationNumber != null) || (this.registrationNumber != null && !this.registrationNumber.equals(other.registrationNumber))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return brand + ", " + model + ", price " + price + "$, RN: " + registrationNumber +
                    ", color: " + colour + ", " + kind;
    }
    
}
